﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using TransCend.DAL;
using TransCend.DB;
using TransCend.Model;
using TransCend.Util.Page;

namespace TransCend.Service
{
    public class CommonService
    {
        public T FindByID<T>(int id) where T : BaseModel
        {
            return CommonDALFactory.GetCommonDAL().FindByID<T>(id);
        }

        public T FindByProperty<T>(string propertyname, object propertyvalue) where T : BaseModel
        {
            return CommonDALFactory.GetCommonDAL().FindByProperty<T>(propertyname, propertyvalue);
        }

        public T FindByPropertys<T>(string[] propertyname, object[] propertyvalue) where T : BaseModel
        {
            return CommonDALFactory.GetCommonDAL().FindByPropertys<T>(propertyname, propertyvalue);
        }

        public int Insert<T>(T model) where T : BaseModel
        {
            return CommonDALFactory.GetCommonDAL().Insert<T>(model);
        }

        public int InserReturnId<T>(T model) where T : BaseModel 
        {
            return CommonDALFactory.GetCommonDAL().InsertReturnId<T>(model);
        }

        public int Update<T>(T model) where T : BaseModel
        {
            return CommonDALFactory.GetCommonDAL().Update<T>(model);
        }

        public int Merge<T>(T model) where T : BaseModel
        {
            return CommonDALFactory.GetCommonDAL().Merge<T>(model);
        }

        public int Delete<T>(int id) where T : BaseModel
        {
            return CommonDALFactory.GetCommonDAL().Delete<T>(id);
        }

        public int Delete<T>(int[] ids) where T : BaseModel
        {
            return CommonDALFactory.GetCommonDAL().Delete<T>(ids);
        }

        /// <summary>
        /// 所有数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public IList<T> FindAll<T>(params OrderBy[] orderBy) where T : BaseModel
        {
            return CommonDALFactory.GetCommonDAL().FindAll<T>(orderBy);
        }

        /// <summary>
        /// 根据单个条件查询列表数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="propertyname"></param>
        /// <param name="propertyvalue"></param>
        /// <returns></returns>
        public IList<T> FindList<T>(string propertyname, object propertyvalue, params OrderBy[] orderBy) where T : BaseModel
        {
            return CommonDALFactory.GetCommonDAL().FindList<T>(propertyname, propertyvalue, orderBy);
        }

        /// <summary>
        /// 多个条件查询列表数据
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="propertynames"></param>
        /// <param name="propertyvalues"></param>
        /// <returns></returns>
        public IList<T> FindList<T>(string[] propertynames, object[] propertyvalues, params OrderBy[] orderBy) where T : BaseModel
        {
            return CommonDALFactory.GetCommonDAL().FindList<T>(propertynames, propertyvalues, orderBy);
        }

        public IList<T> FindList<T>(T queryModel, params OrderBy[] orderBy) where T : BaseModel
        {
            return CommonDALFactory.GetCommonDAL().FindList<T>(queryModel, orderBy);
        }

        public PageTools<T> FindPage<T>(int page, int rows, OrderBy[] orderBy) where T : BaseModel
        {
            return CommonDALFactory.GetCommonDAL().FindPage<T>(page, rows, orderBy);
        }

        public PageTools<T> FindPage<T>(int page, int rows, T queryModel, OrderBy[] orderBy) where T : BaseModel
        {
            return CommonDALFactory.GetCommonDAL().FindPage<T>(page, rows, queryModel, orderBy);
        }

        public DateTime FindNowDate()
        {
            return CommonDALFactory.GetCommonDAL().FindNowDate();
        }
    }
}
